------------------------------------------------//库声明
LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL; 
USE IEEE.STD_LOGIC_UNSIGNED.ALL; 
USE IEEE.STD_LOGIC_ARITH.ALL;

------------------------------------------------//实体定义
ENTITY rom IS
PORT
(   clk_in: in std_logic;
    key3  : in std_logic;
	 led_change  : out integer;
    addr  : IN std_logic_vector(5 downto 0);
	 romzhi: OUT INTEGER RANGE 0 TO 127
	   );
END rom;

------------------------------------------------//结构体定义
ARCHITECTURE behave OF rom IS

------------------------------------------------//信号量定义
signal key_en3: std_logic;
signal count_1: integer range 0 to 250000;
signal rom_change: integer range 0 to 1 :=0;
signal romzhi_temp: std_logic_vector(7 downto 0);
TYPE memory IS ARRAY(0 TO 63) OF std_logic_vector(7 downto 0);

CONSTANT rom_sin: memory:=("00000000","00000000","00000001","00000011",
             "00000101","00000111","00001011","00001110","00010011","00010111","00011100","00100010",
             "00100111","00101101","00110011","00111010","01000000","01000110","01001100","01010010",
             "01011000","01011101","01100010","01101000","01101100","01110001","01110100","01111000",
             "01111010","01111100","01111110","01111111","01111111","01111111","01111110","01111100",
             "01111010","01111000","01110100","01110001","01101100","01101000","01100011","01011101",
             "01011000","01010010","01001100","01000111","01000000","00111001","00110011","00101101",
             "00100111","00100010","00011100","00010111","00010011","00001110","00001011","00000111",
             "00000101","00000011","00000001","00000000");
				 
CONSTANT rom_san: memory:=("00000000","00000010","00001000","00001100",
              "00010000","00010100","00011001","00011101","00100001","00100101","00101001","00101101",
              "00110001","00110101","00111001","00111101","01000010","01000110","01001010","01001110",
              "01010010","01010110","01011010","01011110","01100010","01100110","01101011","01101111",
              "01110011","01110111","01111011","01111111","01111011","01110111","01110011","01101111",
              "01101011","01100111","01100011","01011111","01011011","01010111","01010011","01001111",
              "01001011","01000111","01000011","00111111","00111100","00111000","00110100","00110000",
              "00101100","00101000","00100100","00100000","00011100","00011000","00010100","00010000",
              "00001100","00001000","00000100","00000000");

BEGIN

------------------------------------------------//按键消抖
    process(clk_in)
    begin
        if rising_edge(clk_in) then
            if key3='0' then
                if count_1=250000 then count_1<=count_1;
                else count_1<=count_1+1;
                end if;
                if count_1=249999 then 
                    if key3<='0' then 
                        key_en3<='1';
                    end if;		 
                else 
                    key_en3<='0';
                end if;
            else 
                count_1<=0;
                key_en3<='0';
            end if;
        end if;
    end process;
	 
    process(key_en3)
    begin
        if key_en3='1' then 
            if rom_change=1 then rom_change<=0;
            else rom_change<= rom_change+1;
            end if;
        end if;	
    end process;


------------------------------------------------//rom值产生
    process(addr,rom_change)
        variable addr_temp: INTEGER range 0 to 63;
    begin
        addr_temp := conv_integer(addr);
		  case rom_change is
		      when 0=>romzhi_temp <= rom_sin(addr_temp);
		      when 1=>romzhi_temp <= rom_san(addr_temp);
		  end case;
        romzhi <= conv_integer(romzhi_temp);	
    end process;
	
------------------------------------------------//指示灯	
    process(rom_change,key_en3)
    begin
        if rom_change=0 then led_change<=0;
        else led_change<=1;
        end if;			
    end process;
	
END behave;